<template>
  <div class="hotAuthor">
    <div>热门作者</div>
    <div class="authorBox">
      <div
        class="authorList"
        v-for="item in data"
        :key="item.user_id"
        @click="
          goWrokPage(
            item.web_url,
            item.user_name,
            item.desc,
            item.fans_total,
            item.user_id
          )
        "
      >
        <img :src="item.web_url" alt="" />
        <div class="right">
          <div class="news">
            <div>{{ item.user_name }}</div>
            <div>{{ getLength(item.desc) }}</div>
          </div>
          <div class="gz">关注</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getAuthor } from "@/api/find";
export default {
  name: "hotAuthor",
  data() {
    return {
      data: [],
    };
  },
  created() {
    this.getHotAuthor();
  },

  methods: {
    async getHotAuthor() {
      const { data } = await getAuthor();
      this.data = data;
      console.log("热门作者", this.data);
    },
    goWrokPage(img, name, desc, total, id) {
      this.$router.push({
        path: "/authorWork",
        query: {
          id: id,
        },
      });
    },
    // 处理字数长度的方法
    getLength(str) {
      if (str.length > 15) {
        return str.substr(0, 18) + "...";
      } else {
        return str;
      }
    },
  },
};
</script>

<style lang="less" scoped>
.hotAuthor {
  width: 375px;
  padding: 0 15px 50px 15px;
  .authorBox {
    width: 100%;
    .authorList {
      width: 100%;
      display: flex;
      margin: 20px 0;
      box-sizing: border-box;
      img {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        margin-right: 15px;
      }
      .right {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        .news {
          & > :nth-child(1) {
            font-size: 16px;
            color: #000;
            padding-bottom: 8px;
          }
          & > :nth-child(2) {
            font-size: 12px;
            color: #cbcbcb;
          }
        }
        .gz {
          width: 40px;
          height: 20px;
          border: 1px solid #000;
          border-radius: 20px;
          font-size: 12px;
          text-align: center;
          line-height: 20px;
        }
      }
    }
  }
}
</style>